package com.gegong.vmware.workstation.exceptions;

import com.gegong.vmware.workstation.RestResponse;
import com.gegong.vmware.workstation.VMwareWorkstationManagementActions;
import com.gegong.vmware.workstation.VMwareWorkstationManagementProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = false)
@Data
public class RestApiAccessException extends VMwareWorkstationManagementException {

    private VMwareWorkstationManagementActions.BaseAction action;

    public RestApiAccessException(VMwareWorkstationManagementActions.BaseAction action) {
        super(String.format("访问%s:%s异常", action.getUri(), action.getMethod()));
        this.action = action;
    }

    public RestApiAccessException(VMwareWorkstationManagementActions.BaseAction action, Throwable cause) {
        super(String.format("访问%s:%s异常", action.getUri(), action.getMethod()), cause);
        this.action = action;
    }

    public RestApiAccessException(VMwareWorkstationManagementActions.BaseAction action, RestResponse.ErrorResponse errorResponse) {
        super(String.format("访问%s%s[method %s]异常,响应内容:%s", VMwareWorkstationManagementProperties.restApiRootUrl, action.getUri(), action.getMethod(), errorResponse.toJsonString()));
        this.action = action;
    }
}
